if(!dojo._hasResource["opm.widgets.component.ApplicationProperty"]){
dojo._hasResource["opm.widgets.component.ApplicationProperty"] = true;
dojo.provide("opm.widgets.component.ApplicationProperty");
dojo.require("dijit._Widget");
dojo.require("opm.widgets.Ajax");
dojo.require("opm.widgets.GenericForm");
dojo.require("opm.widgets.GenericPage");
dojo.require("opm.widgets.GenericFormDialog");
dojo.declare("opm.widgets.component.ApplicationProperty",dijit._Widget,
{
   contentId:"",
   defaultURL:"",
   _GENERIC_PAGE:"opm.widgets.ApplicationProperty.genericPage",
   _GENERIC_ADD_FORM:"opm.widgets.ApplicationProperty.addForm",
   _GENERIC_EDIT_FORM:"opm.widgets.ApplicationProperty.editForm",
   
   constructor:function(args){
      this.setAtts(args);
   },
   setAtts:function(args){
      this.contentId = args.contentId;
   },
   displayApplicationProperties:function(){
      var args = {ajaxUrl: this.defaultURL, callback: this._initApplicationProperty};
      OPM.ajaxWidget(args, this.contentId).callXhrGet();
   },

   showAddForm:function(ajaxUrl){
      var dataform = {
         ajaxCallUrl: ajaxUrl, 
         ajaxCallType:'callXhrGetJson',
         contentId: this.contentId,
         widgetId: this._GENERIC_ADD_FORM
      };
      var genericForm = this.commonForm(dataform);
      genericForm.createForm();
   },

   showEditForm:function(ajaxUrl){
      var dataform = {
         ajaxCallUrl: ajaxUrl, 
         ajaxCallType:'callXhrGetJson',
         contentId: this.contentId,
         widgetId: this._GENERIC_EDIT_FORM
      };
      var genericForm = this.commonForm(dataform);
      genericForm.createForm();
   },

   commonForm:function(dataform){
      var genericForm = OPM.genericFormWidget(dataform);
      genericForm.connectEvent("btnCancelClick", function(data){
         OPM.applicationPropertyWidget().displayApplicationProperties();
      });
      genericForm.connectEvent("btnAddClick", function(data){
         genericForm.callSaveForm({handleSuccess:function(){
            OPM.applicationPropertyWidget().displayApplicationProperties();
         }});
      });
      return genericForm;
   },

   _initApplicationProperty:function(){
      dojo.query('#hrefViewAddPropertyDef').onclick(function(){
         OPM.applicationPropertyWidget().showAddForm(dojo.byId('viewAddPropertyDef').value);
      });

      dojo.query('table#classInst tbody tr').connect('ondblclick', function(evt){
         var editUrl = dojo.query('input[type="hidden"]', this)[0].value;
         OPM.applicationPropertyWidget().showEditForm(editUrl);
      });
   }
}
);
}
